import React, {Component} from 'react';
import pubSub from "pubsub-js";

class Search extends Component {
    keyword=React.createRef();
    render() {
        return (
            <section className="jumbotron">
                <h3 className="jumbotron-heading">Search Github Users</h3>
                <div>
                    <input ref={this.keyword} type="text" placeholder="enter the name you search"/>
                    <button onClick={()=>{
                        const keyword = this.keyword.current.value.trim();
                        if(keyword.length>0){
                            pubSub.publish("search",keyword);
                        }else{
                            alert("请输入搜索的内容")
                        }
                    }}>Search</button>
                </div>
            </section>
        );
    }
}

export default Search;